#!/usr/bin/env ruby
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
# frozen_string_literal: true

require 'set'
require_relative '../defconfig.rb'

names = Set.new %w[
  LOGGING_ES_USER
  LOGGING_ES_PASSWORD
]

defaults = relevant_service_authentication(names)
docker_skip_rebuild 'logging-es:7.11.1'

BASE_IMAGE_DICT = {
  'aarch64' => 'elasticsearch:7.11.1@sha256:d52cda1e73d1b1915ba2d76ca1e426620c7b5d6942d9d2f432259503974ba786',
  'x86_64' => 'elasticsearch:7.11.1'
}.freeze

BASE_IMAGE = BASE_IMAGE_DICT[%x(arch).chomp]

ARCH = %x(arch).chomp

available_memory = get_available_memory

system "docker build --no-cache -t logging-es:7.11.1 --progress=plain --build-arg BASE_IMAGE=#{BASE_IMAGE} --build-arg MEMORY=#{available_memory} --build-arg USER=#{defaults['LOGGING_ES_USER']} --build-arg PASSWORD=#{defaults['LOGGING_ES_PASSWORD']} --build-arg ARCH=#{ARCH} ."

push_image_remote "logging-es:7.11.1"
